﻿// Copyright 2010 Maxime Serrano <lastchronicler@gmail.com>
using System;
using System.IO;
using System.Text;

namespace MCSharp.Network
{
    sealed class PacketReader
    {
        public static string ReadString(BinaryReader reader)
        {
            try
            {
                short strLen = PacketWriter.SwapEndian((short)reader.ReadUInt16());
                string str = UTF8Encoding.UTF8.GetString(reader.ReadBytes(strLen)).Trim();
                return str;
            }
            catch (Exception e)
            {
                Logger.Log("Session.ReadString: Error reading input string: {0}", LogType.Error, e);
                return "";
            }
        }
    }
}
